package 单例模式;

/**
 * @author zzs
 * @ClassName Single3.java
 * @Description 需要配合volatile，防止指令重排序产生不可预估的问题
 * @createTime 2022年05月14日 20:35:00
 */
public class Single3 {
    private volatile static Single3 single3;

    private Single3() {
        System.out.println("双重检查锁初始化");
    }

    public synchronized static Single3 getSingle() {
        if (single3 == null) {
            synchronized (Single3.class) {
                if (single3 == null) {
                    single3 = new Single3();
                }
            }
        }
        return single3;
    }
}
